home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / rkrm_lib3 / rkrm_lib3.lha / Math / ffpexample.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  4KB  |  100 lines

  1. ;/* FFPExample.c
  2. LC -cfist -ff -v -y -j73 FFPExample.c
  3. Blink FROM LIB:c.o,FFPExample.o TO FFPExample LIBRARY lib:lcmffp.lib,LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33.  
  34. #include <exec/types.h>
  35. #include <libraries/mathffp.h>
  36.  
  37. #include <clib/exec_protos.h>
  38. #include <clib/mathffp_protos.h>
  39. #include <clib/alib_protos.h>
  40. #include <clib/alib_stdio_protos.h>
  41.  
  42. struct Library *MathBase;
  43.  
  44. UBYTE st1[80] = "3.1415926535897";
  45. UBYTE st2[80] = "2.718281828459045";
  46. UBYTE st3[80], st4[80];
  47.  
  48. VOID main(VOID)
  49. {
  50. FLOAT num1, num2;
  51. FLOAT n1, n2, n3, n4;
  52. LONG  exp1, exp2, exp3, exp4;
  53. LONG  mant1, mant2, mant3, mant4;
  54. LONG  place1, place2;
  55.  
  56. if (MathBase = OpenLibrary("mathffp.library", 33))
  57.     {
  58.  
  59.     n1 = afp(st1);            /* Call afp entry */
  60.     n2 = afp(st2);            /* Call afp entry */
  61.     printf("\n\nASCII %s converts to floating point %f", st1, n1);
  62.     printf("\nASCII %s converts to floating point %f", st2, n2);
  63.  
  64.     num1 = 3.1415926535897;
  65.     num2 = 2.718281828459045;
  66.  
  67.     exp1 = fpa(num1, st3);    /* Call fpa entry */
  68.     exp2 = fpa(num2, st4);    /* Call fpa entry */
  69.     printf("\n\nfloating point %f converts to ASCII %s", num1, st3);
  70.     printf("\nfloating point %f converts to ASCII %s", num2, st4);
  71.  
  72.     place1 = -2;
  73.     place2 = -1;
  74.     arnd(place1, exp1, st3);    /* Call arnd entry */
  75.     arnd(place2, exp2, st4);    /* Call arnd entry */
  76.     printf("\n\nASCII round of %f to %d places yields %s", num1, place1, st3);
  77.     printf("\nASCII round of %f to %d places yields %s", num2, place2, st4);
  78.  
  79.     exp1  = -3;    exp2  = 3;    exp3  = -3;    exp4  = 3;
  80.     mant1 = 12345;    mant2 = -54321;    mant3 = -12345;    mant4 = 54321;
  81.  
  82.     n1 = dbf(exp1, mant1);        /* Call dbf entry */
  83.     n2 = dbf(exp2, mant2);        /* Call dbf entry */
  84.     n3 = dbf(exp3, mant3);        /* Call dbf entry */
  85.     n4 = dbf(exp4, mant4);        /* Call dbf entry */
  86.     printf("\n\ndbf of exp = %d and mant = %d yields FFP number of %f",
  87.            exp1, mant1, n1);
  88.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f",
  89.            exp2, mant2, n2);
  90.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f",
  91.            exp3, mant3, n3);
  92.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f\n",
  93.            exp4, mant4, n4);
  94.  
  95.     CloseLibrary(MathBase);
  96.     }
  97. else
  98.     printf("Can't open mathffp.library\n");
  99. }
  100.